package com.syl.whitelist.utils;

import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.AnnotatedElementUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @ClassName AnnotatedMethodsUtils
 * @Description 获取注解方法
 * @Author YunLong
 * @Date 2022/8/19 15:16
 */
public class AnnotatedMethodsUtils {
    private AnnotatedMethodsUtils() {
    }

    public static <T extends Annotation> Map<Method, T> getMethodAndAnnotation(Object bean, Class<T> annotation) {
        return MethodIntrospector.selectMethods(bean.getClass(),
                (MethodIntrospector.MetadataLookup<T>) method -> AnnotatedElementUtils
                        .findMergedAnnotation(method, annotation));
    }
}
